package com.baozou.framework.util;

import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;

public class AssetsUtil {
	
	Context context;
	
	public AssetsUtil(Context context){
		this.context = context;
	}
	public String[] getPicNames(){
		String[] picNames = null;
    	try {
			picNames = context.getAssets().list("pic");
			for(String str : picNames){
				Log.d(this.toString(), str);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return picNames;
    }
    
    public Drawable getDrawableFromAssets(String fileName) throws Exception{
        Bitmap b = getBitmapFromAssets(fileName);
        Drawable d = new BitmapDrawable(b);
        
        return d;
    }
    
    public Bitmap getBitmapFromAssets(String fileName) throws Exception{
    	InputStream in = context.getAssets().open("pic/"+fileName);
        Bitmap b = BitmapFactory.decodeStream(in);

        return b;
    }
}
